package com.buildings.http;

import android.content.Context;

import org.json.JSONException;
import org.json.JSONObject;


public class JsonBuilder {
    
    private JSONObject json = null;

    private Context mContext;


    private long nowTime ;

    public JsonBuilder(Context context) {

        this.mContext = context;

        json = new JSONObject();

//        if (SPUtil.contain("uid")) {
//            put("uid", SPUtil.get("uid",0));
//        }else {
//            put("uid", 0);
//        }
//
//        if (SPUtil.contain("password")) {
//            put("token", MD5.md5((String) SPUtil.get("password","")));
//        }else {
//            put("token",MD5.md5(""));
//        }
//
//        long nowTime2  = System.currentTimeMillis();
//        nowTime = Long.parseLong(String.valueOf(nowTime2).toString().substring(0,10));//当前时间戳
//        put("timestamp",nowTime);
    }
    public JSONObject getJson() {
        return json;
    }

    public void put(String name, boolean value) {

        try {
            json.put(name, value);
        }
        catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    public void put(String name, int value) {
        try {
            json.put(name, value);
        }
        catch (JSONException e) {
            e.printStackTrace();
        }
    }
    
    public void put(String name, long value) {
        try {
            json.put(name, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    
    public void put(String name, double value) {
        try {
            json.put(name, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    
    public void put(String name, Object value) {
        try {
            json.put(name, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    
    public void putOpt(String name, Object value) {
        try {
            json.putOpt(name, value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    
    public String toJsonString() {

        return json.toString();
    }
}
